﻿namespace QLPhongKham.UC
{
    using ConfigDatabase.Class;
    using DevExpress.Data;
    using DevExpress.Utils;
    using DevExpress.XtraEditors;
    using DevExpress.XtraEditors.Mask;
    using DevExpress.XtraEditors.Repository;
    using DevExpress.XtraGrid;
    using DevExpress.XtraGrid.Columns;
    using DevExpress.XtraGrid.Views.Base;
    using DevExpress.XtraGrid.Views.Grid;
    using DevExpress.XtraTab;
    using QLPhongKham.Access;
    using QLPhongKham.Access.Duoc;
    using QLPhongKham.BaseClass.Duoc;
    using QLPhongKham.Report;
    using System;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.IO;
    using System.Windows.Forms;
    using UserControls;

    public class ucd_dmquydoi : XtraUserControl
    {
        private ConnectDatabase _condata;
        private dtoDDMQuyDoi _dto;
        private dtoDDMDuocPham _dtodp;
        private General _xuli;
        private SimpleButton btnboqua;
        private SimpleButton btnimport;
        private SimpleButton btnin;
        private SimpleButton btnketthuc;
        private SimpleButton btnluu;
        private SimpleButton btnmoi;
        private SimpleButton btnsua;
        private SimpleButton btnxoa;
        private IContainer components;
        private ctrdanhsach ctrdanhsach_vp;
        private GridControl gridds;
        private GridColumn gridds_dvt;
        private GridColumn gridds_id;
        private GridColumn gridds_iddp;
        private GridColumn gridds_ma;
        private GridColumn gridds_quydoi;
        private GridColumn gridds_soluong;
        private GridColumn gridds_ten;
        private GridView gridView1;
        private Label label1;
        private Label label2;
        private Label label3;
        private RepositoryItemTextEdit repositoryItemTextEdit1;
        private TextEdit txtdvt;
        private TextEdit txtma;
        private TextEdit txtsoluong;
        private TextEdit txtten;
        private TextEdit txttenduocpham;

        public ucd_dmquydoi()
        {
            this.components = null;
            this.InitializeComponent();
            this._condata = new ConnectDatabase();
        }

        public ucd_dmquydoi(ConnectDatabase condata)
        {
            this.components = null;
            this.InitializeComponent();
            this._condata = condata;
        }

        public ucd_dmquydoi(ConnectDatabase condata, dtoDDMDuocPham dtodp)
        {
            this.components = null;
            this.InitializeComponent();
            this._condata = condata;
            this._dtodp = dtodp;
        }

        private void btnboqua_Click(object sender, EventArgs e)
        {
            this.f_Control_enable(false);
        }

        private void btnimport_Click(object sender, EventArgs e)
        {
            OpenFileDialog dialog = new OpenFileDialog {
                Title = "Chọn file excel dữ liệu",
                Filter = "(Excel 2003).xls|*.xls|(Execel 2007).xlsx|*.xlsx",
                FilterIndex = 0,
                Multiselect = false
            };
            dialog.ShowDialog();
            if (dialog.FileName != "")
            {
                string fileName = dialog.FileName;
                DataTable table = this._xuli.f_getdata_fromfileExcel(fileName, "Sheet");
                if (table.Columns.Count != 6)
                {
                    MessageBox.Show("Định dạng file excel kh\x00f4ng đ\x00fang.\nVui l\x00f2ng kiểm tra lại:1.Số thứ tự\n2.M\x00e3 số\n3.T\x00ean viện ph\x00ed.\n4.Đơn vị t\x00ednh.\n5.H\x00e0m lượng.\n6.Hoạt chất.", "Th\x00f4ng b\x00e1o");
                }
                else if ((table.Rows.Count <= 0) || (MessageBox.Show("Bạn c\x00f3 muốn th\x00eam dữ liệu từ file excel v\x00e0o dữ liệu hiện tại kh\x00f4ng?\nChọn Yes để chấp nhận.\nChọn No để bỏ qua thao t\x00e1c.", "Th\x00f4ng b\x00e1o", MessageBoxButtons.YesNo, MessageBoxIcon.Question) != DialogResult.No))
                {
                    dtoDDMDuocPham pham = new dtoDDMDuocPham(this._xuli.pConFigData);
                    if ((MessageBox.Show("Bạn c\x00f3 muốn hủy dữ liệu hiện tại kh\x00f4ng?\nChọn Yes để chấp nhận.\nChọn No để bỏ qua thao t\x00e1c.", "Th\x00f4ng b\x00e1o", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) && !pham.Delete())
                    {
                        MessageBox.Show("Hủy dữ liệu kh\x00f4ng th\x00e0nh c\x00f4ng.", "Th\x00f4ng b\x00e1o");
                    }
                    else
                    {
                        string str2 = "";
                        for (int i = 0; i < table.Rows.Count; i++)
                        {
                            if (table.Rows[i][table.Columns.Count - 1].ToString() != "")
                            {
                                pham = new dtoDDMDuocPham(this._xuli.pConFigData) {
                                    pID = pham.GetIDInsert()
                                };
                                try
                                {
                                    pham.pSTT = int.Parse(table.Rows[i][0].ToString());
                                }
                                catch
                                {
                                }
                                pham.pMA = table.Rows[i][1].ToString();
                                pham.pTEN = table.Rows[i][2].ToString();
                                pham.pDVT = table.Rows[i][3].ToString();
                                pham.pHAMLUONG = table.Rows[i][4].ToString();
                                pham.pTENHOATCHAT = table.Rows[i][5].ToString();
                                if (!pham.Insert())
                                {
                                    object obj2 = str2;
                                    str2 = string.Concat(new object[] { obj2, "\n", pham.pSTT, "-", pham.pTEN, "-", pham.pDVT, "-", pham.pMA, ";" });
                                }
                            }
                        }
                        if (str2 != "")
                        {
                            MessageBox.Show("C\x00e1c dữ liệu sau bị lỗi:" + str2, "Th\x00f4ng b\x00e1o");
                        }
                        this.f_loaddata_quydoi();
                    }
                }
            }
        }

        private void btnin_Click(object sender, EventArgs e)
        {
            DataTable dataSource = (DataTable) this.gridds.DataSource;
            dataSource.AcceptChanges();
            DataSet data = new DataSet();
            data.Tables.Add(dataSource.Copy());
            try
            {
                data.WriteXml(Directory.GetCurrentDirectory() + @"\dataxml\d_dmquydoi.xml", XmlWriteMode.WriteSchema);
            }
            catch
            {
            }
            new XtraReport1().f_load(data, "repx_d_dmduocpham.repx");
        }

        private void btnketthuc_Click(object sender, EventArgs e)
        {
            try
            {
                XtraTabPage parent = (XtraTabPage) base.Parent;
                XtraTabControl control = (XtraTabControl) parent.Parent;
                control.TabPages.Remove(parent);
            }
            catch
            {
                try
                {
                    UserControl control2 = (UserControl) base.Parent;
                    control2.Controls.Remove(this);
                }
                catch
                {
                }
            }
        }

        private void btnluu_Click(object sender, EventArgs e)
        {
            this._dto = new dtoDDMQuyDoi(this._condata);
            this._dto.pIDDUOCPHAM = int.Parse(this.txttenduocpham.Tag.ToString());
            this._dto.pSOLUONG = Convert.ToDecimal(this.txtsoluong.EditValue);
            this._dto.pTEN = this.txtten.Text;
            this._dto.pID = int.Parse(this.txtma.Tag.ToString());
            if (this.txtma.Tag.ToString() == "0")
            {
                this._dto.pID = this._dto.GetIDInsert();
                if (!this._dto.Insert())
                {
                    MessageBox.Show("Kh\x00f4ng lưu được th\x00f4ng tin quy đổi", "Th\x00f4ng b\x00e1o");
                    return;
                }
            }
            else if (!this._dto.Update())
            {
                MessageBox.Show("Kh\x00f4ng lưu được th\x00f4ng tin quy đổi", "Th\x00f4ng b\x00e1o");
                return;
            }
            this.f_loaddata_quydoi();
            this.f_Control_enable(false);
        }

        private void btnmoi_Click(object sender, EventArgs e)
        {
            this.f_Loadcontrol_dmvp(0L, 0L, "", "", "", 0M, "");
            this.f_Control_enable(true);
            base.ActiveControl = this.txtma;
        }

        private void btnsua_Click(object sender, EventArgs e)
        {
            this.f_Control_enable(true);
            this.txttenduocpham.Focus();
        }

        private void btnxoa_Click(object sender, EventArgs e)
        {
            if ((this.txtma.Tag.ToString() != "0") && (MessageBox.Show("Bạn c\x00f3 chắc chắn muốn hủy th\x00f4ng tin:\n" + this.txtma.Text + " - " + this.txttenduocpham.Text + " - " + this.txtten.Text + " ?", "Th\x00f4ng b\x00e1o", MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation) != DialogResult.No))
            {
                try
                {
                    this._dto = new dtoDDMQuyDoi(this._condata);
                    this._dto.pID = int.Parse(this.txtma.Tag.ToString());
                    if (!this._dto.Delete())
                    {
                        MessageBox.Show("Hủy kh\x00f4ng th\x00e0nh c\x00f4ng.Vui l\x00f2ng kiểm tra lại.", "Th\x00f4ng b\x00e1o");
                    }
                    else
                    {
                        MessageBox.Show("Đ\x00e3 hủy th\x00e0nh c\x00f4ng.", "Th\x00f4ng b\x00e1o");
                        this.f_loaddata_quydoi();
                    }
                }
                catch
                {
                }
            }
        }

        private void ctrdanhsach_vp_Validated(object sender, EventArgs e)
        {
            DataTable dongHienTai = this.ctrdanhsach_vp.DongHienTai;
            try
            {
                this.f_load_thongtinduocpham(int.Parse(dongHienTai.Rows[0]["id"].ToString()), dongHienTai.Rows[0]["ma"].ToString(), dongHienTai.Rows[0]["ten"].ToString(), dongHienTai.Rows[0]["dvt"].ToString());
            }
            catch
            {
                this.f_load_thongtinduocpham(0, "", "", "");
            }
        }

        protected override void Dispose(bool disposing)
        {
            if (disposing && (this.components != null))
            {
                this.components.Dispose();
            }
            base.Dispose(disposing);
        }

        private void f_Control_enable(bool chophep)
        {
            this.btnluu.Enabled = this.btnboqua.Enabled = chophep;
            this.btnmoi.Enabled = this.btnxoa.Enabled = this.btnsua.Enabled = this.btnketthuc.Enabled = !chophep;
            this.gridds.Enabled = !chophep;
        }

        private void f_load_thongtinduocpham(int iddp, string madp, string tendp, string dvt)
        {
            this.txtdvt.Text = dvt;
            this.txttenduocpham.Text = tendp;
            this.txtma.Text = madp;
            this.txttenduocpham.Tag = iddp;
        }

        private void f_Loadcontrol_dmvp(long id, long iddp, string madp, string tendp, string dvt, decimal soluong, string tenquydoi)
        {
            this.txtma.Text = madp;
            this.txtma.Tag = id.ToString();
            this.txttenduocpham.Tag = iddp.ToString();
            this.txttenduocpham.Text = tendp;
            this.txtdvt.Text = dvt;
            this.txtsoluong.EditValue = soluong;
            this.txtten.Text = tenquydoi;
        }

        private void f_loaddata_dmduocpham()
        {
            try
            {
                DataTable table = new dtoDDMDuocPham(this._condata).LoadAll();
                this.ctrdanhsach_vp.SetDataSource = table;
                this.ctrdanhsach_vp.DanhSachCotHienThi = "ma,ten,dvt";
            }
            catch
            {
            }
        }

        private void f_loaddata_quydoi()
        {
            try
            {
                this.gridds.DataSource = new DDuocPham(this._condata).f_loaddata_dmquydoi(0L);
            }
            catch
            {
            }
        }

        private void f_loadinfo_dmsanpham(int indexrow)
        {
            try
            {
                this.f_Loadcontrol_dmvp(long.Parse(this.gridView1.GetRowCellValue(indexrow, this.gridds_id).ToString()), long.Parse(this.gridView1.GetRowCellValue(indexrow, this.gridds_iddp).ToString()), this.gridView1.GetRowCellValue(indexrow, this.gridds_ma).ToString(), this.gridView1.GetRowCellValue(indexrow, this.gridds_ten).ToString(), this.gridView1.GetRowCellValue(indexrow, this.gridds_dvt).ToString(), decimal.Parse(this.gridView1.GetRowCellValue(indexrow, this.gridds_soluong).ToString()), this.gridView1.GetRowCellValue(indexrow, this.gridds_quydoi).ToString());
            }
            catch
            {
            }
        }

        private void gridView1_CustomSummaryCalculate(object sender, CustomSummaryEventArgs e)
        {
        }

        private void gridView1_FocusedRowChanged(object sender, FocusedRowChangedEventArgs e)
        {
            int indexrow = 0;
            try
            {
                if (this.gridView1.IsFocusedView)
                {
                    indexrow = this.gridView1.GetSelectedRows()[0];
                    this.f_loadinfo_dmsanpham(indexrow);
                }
            }
            catch
            {
            }
        }

        private void InitializeComponent()
        {
            ComponentResourceManager manager = new ComponentResourceManager(typeof(ucd_dmquydoi));
            this.label1 = new Label();
            this.label2 = new Label();
            this.txtma = new TextEdit();
            this.txttenduocpham = new TextEdit();
            this.txtdvt = new TextEdit();
            this.btnmoi = new SimpleButton();
            this.btnluu = new SimpleButton();
            this.btnsua = new SimpleButton();
            this.btnxoa = new SimpleButton();
            this.btnketthuc = new SimpleButton();
            this.gridView1 = new GridView();
            this.gridds_ma = new GridColumn();
            this.repositoryItemTextEdit1 = new RepositoryItemTextEdit();
            this.gridds_ten = new GridColumn();
            this.gridds_dvt = new GridColumn();
            this.gridds_id = new GridColumn();
            this.gridds_soluong = new GridColumn();
            this.gridds_quydoi = new GridColumn();
            this.gridds_iddp = new GridColumn();
            this.gridds = new GridControl();
            this.btnboqua = new SimpleButton();
            this.btnin = new SimpleButton();
            this.btnimport = new SimpleButton();
            this.ctrdanhsach_vp = new ctrdanhsach();
            this.label3 = new Label();
            this.txtten = new TextEdit();
            this.txtsoluong = new TextEdit();
            this.txtma.Properties.BeginInit();
            this.txttenduocpham.Properties.BeginInit();
            this.txtdvt.Properties.BeginInit();
            this.gridView1.BeginInit();
            this.repositoryItemTextEdit1.BeginInit();
            this.gridds.BeginInit();
            this.txtten.Properties.BeginInit();
            this.txtsoluong.Properties.BeginInit();
            base.SuspendLayout();
            this.label1.BackColor = Color.ForestGreen;
            this.label1.Dock = DockStyle.Top;
            this.label1.Font = new Font("Tahoma", 16f);
            this.label1.ForeColor = Color.Yellow;
            this.label1.Location = new Point(0, 0);
            this.label1.Name = "label1";
            this.label1.Size = new Size(0x392, 0x30);
            this.label1.TabIndex = 1;
            this.label1.Text = "DANH MỤC QUY ĐỔI";
            this.label1.TextAlign = ContentAlignment.MiddleCenter;
            this.label2.Anchor = AnchorStyles.Left | AnchorStyles.Bottom;
            this.label2.Font = new Font("Tahoma", 10f);
            this.label2.Location = new Point(0, 0x16c);
            this.label2.Name = "label2";
            this.label2.Size = new Size(90, 0x13);
            this.label2.TabIndex = 2;
            this.label2.Text = "Dược phẩm:";
            this.label2.TextAlign = ContentAlignment.TopRight;
            this.txtma.Anchor = AnchorStyles.Left | AnchorStyles.Bottom;
            this.txtma.Location = new Point(0x60, 0x16b);
            this.txtma.Name = "txtma";
            this.txtma.Properties.CharacterCasing = CharacterCasing.Upper;
            this.txtma.Size = new Size(0x4d, 20);
            this.txtma.TabIndex = 0;
            this.txtma.KeyDown += new KeyEventHandler(this.ucDMSanPham_KeyDown);
            this.txttenduocpham.Anchor = AnchorStyles.Right | AnchorStyles.Left | AnchorStyles.Bottom;
            this.txttenduocpham.Location = new Point(0xb0, 0x16b);
            this.txttenduocpham.Name = "txttenduocpham";
            this.txttenduocpham.Size = new Size(0x1f9, 20);
            this.txttenduocpham.TabIndex = 1;
            this.txttenduocpham.TextChanged += new EventHandler(this.txttenduocpham_TextChanged);
            this.txttenduocpham.Enter += new EventHandler(this.txttenduocpham_Enter);
            this.txttenduocpham.KeyDown += new KeyEventHandler(this.txttenduocpham_KeyDown);
            this.txttenduocpham.Validated += new EventHandler(this.txtten_Validated);
            this.txtdvt.Anchor = AnchorStyles.Right | AnchorStyles.Bottom;
            this.txtdvt.Location = new Point(0x35b, 0x16b);
            this.txtdvt.Name = "txtdvt";
            this.txtdvt.Properties.ReadOnly = true;
            this.txtdvt.Size = new Size(0x31, 20);
            this.txtdvt.TabIndex = 14;
            this.txtdvt.KeyDown += new KeyEventHandler(this.ucDMSanPham_KeyDown);
            this.btnmoi.Anchor = AnchorStyles.Bottom;
            this.btnmoi.Appearance.Options.UseTextOptions = true;
            this.btnmoi.Appearance.TextOptions.HAlignment = HorzAlignment.Near;
            this.btnmoi.Image = Properties.Resources.imgnew;// (Image)manager.GetObject("btnmoi.Image");
            this.btnmoi.Location = new Point(0x62, 0x185);
            this.btnmoi.Name = "btnmoi";
            this.btnmoi.Size = new Size(0x4b, 0x17);
            this.btnmoi.TabIndex = 6;
            this.btnmoi.Text = " &Mới [F2]";
            this.btnmoi.Click += new EventHandler(this.btnmoi_Click);
            this.btnluu.Anchor = AnchorStyles.Bottom;
            this.btnluu.Appearance.Options.UseTextOptions = true;
            this.btnluu.Appearance.TextOptions.HAlignment = HorzAlignment.Near;
            this.btnluu.Image = Properties.Resources.imgsave;// (Image)manager.GetObject("btnluu.Image");
            this.btnluu.Location = new Point(0xb0, 0x185);
            this.btnluu.Name = "btnluu";
            this.btnluu.Size = new Size(0x4b, 0x17);
            this.btnluu.TabIndex = 5;
            this.btnluu.Text = " &Lưu [F5]";
            this.btnluu.Click += new EventHandler(this.btnluu_Click);
            this.btnsua.Anchor = AnchorStyles.Bottom;
            this.btnsua.Appearance.Options.UseTextOptions = true;
            this.btnsua.Appearance.TextOptions.HAlignment = HorzAlignment.Near;
            this.btnsua.Image = Properties.Resources.imgedit;// (Image)manager.GetObject("btnsua.Image");
            this.btnsua.Location = new Point(0xfe, 0x185);
            this.btnsua.Name = "btnsua";
            this.btnsua.Size = new Size(0x4b, 0x17);
            this.btnsua.TabIndex = 7;
            this.btnsua.Text = " &Sửa [F3]";
            this.btnsua.Click += new EventHandler(this.btnsua_Click);
            this.btnxoa.Anchor = AnchorStyles.Bottom;
            this.btnxoa.Image = Properties.Resources.imgdelete;// (Image)manager.GetObject("btnxoa.Image");
            this.btnxoa.Location = new Point(0x1a5, 0x185);
            this.btnxoa.Name = "btnxoa";
            this.btnxoa.Size = new Size(0x4b, 0x17);
            this.btnxoa.TabIndex = 9;
            this.btnxoa.Text = " &Hủy [F7]";
            this.btnxoa.Click += new EventHandler(this.btnxoa_Click);
            this.btnketthuc.Anchor = AnchorStyles.Right | AnchorStyles.Bottom;
            this.btnketthuc.Appearance.Options.UseTextOptions = true;
            this.btnketthuc.Appearance.TextOptions.HAlignment = HorzAlignment.Near;
            this.btnketthuc.Image = Properties.Resources.imgclose;// (Image)manager.GetObject("btnketthuc.Image");
            this.btnketthuc.Location = new Point(0x327, 0x188);
            this.btnketthuc.Name = "btnketthuc";
            this.btnketthuc.Size = new Size(0x65, 0x17);
            this.btnketthuc.TabIndex = 13;
            this.btnketthuc.Text = " &Kết th\x00fac [F12]";
            this.btnketthuc.Click += new EventHandler(this.btnketthuc_Click);
            this.gridView1.Appearance.ColumnFilterButton.BackColor = Color.FromArgb(0xca, 0xdd, 0xd0);
            this.gridView1.Appearance.ColumnFilterButton.BorderColor = Color.FromArgb(0xca, 0xdd, 0xd0);
            this.gridView1.Appearance.ColumnFilterButton.ForeColor = Color.Black;
            this.gridView1.Appearance.ColumnFilterButton.Options.UseBackColor = true;
            this.gridView1.Appearance.ColumnFilterButton.Options.UseBorderColor = true;
            this.gridView1.Appearance.ColumnFilterButton.Options.UseForeColor = true;
            this.gridView1.Appearance.ColumnFilterButtonActive.BackColor = Color.FromArgb(0xd3, 0xe2, 0xd8);
            this.gridView1.Appearance.ColumnFilterButtonActive.BorderColor = Color.FromArgb(0xd3, 0xe2, 0xd8);
            this.gridView1.Appearance.ColumnFilterButtonActive.ForeColor = Color.Black;
            this.gridView1.Appearance.ColumnFilterButtonActive.Options.UseBackColor = true;
            this.gridView1.Appearance.ColumnFilterButtonActive.Options.UseBorderColor = true;
            this.gridView1.Appearance.ColumnFilterButtonActive.Options.UseForeColor = true;
            this.gridView1.Appearance.Empty.BackColor = Color.FromArgb(0xf2, 0xf4, 0xec);
            this.gridView1.Appearance.Empty.BackColor2 = Color.White;
            this.gridView1.Appearance.Empty.Options.UseBackColor = true;
            this.gridView1.Appearance.EvenRow.BackColor = Color.FromArgb(0xdd, 0xe3, 0xf5);
            this.gridView1.Appearance.EvenRow.BorderColor = Color.FromArgb(0xdd, 0xe3, 0xf5);
            this.gridView1.Appearance.EvenRow.ForeColor = Color.Black;
            this.gridView1.Appearance.EvenRow.Options.UseBackColor = true;
            this.gridView1.Appearance.EvenRow.Options.UseBorderColor = true;
            this.gridView1.Appearance.EvenRow.Options.UseForeColor = true;
            this.gridView1.Appearance.FilterCloseButton.BackColor = Color.FromArgb(0xca, 0xdd, 0xd0);
            this.gridView1.Appearance.FilterCloseButton.BorderColor = Color.FromArgb(0xca, 0xdd, 0xd0);
            this.gridView1.Appearance.FilterCloseButton.ForeColor = Color.Black;
            this.gridView1.Appearance.FilterCloseButton.Options.UseBackColor = true;
            this.gridView1.Appearance.FilterCloseButton.Options.UseBorderColor = true;
            this.gridView1.Appearance.FilterCloseButton.Options.UseForeColor = true;
            this.gridView1.Appearance.FilterPanel.BackColor = Color.FromArgb(0xf2, 0xf4, 0xec);
            this.gridView1.Appearance.FilterPanel.BackColor2 = Color.White;
            this.gridView1.Appearance.FilterPanel.ForeColor = Color.Black;
            this.gridView1.Appearance.FilterPanel.Options.UseBackColor = true;
            this.gridView1.Appearance.FilterPanel.Options.UseForeColor = true;
            this.gridView1.Appearance.FixedLine.BackColor = Color.FromArgb(0x75, 0x88, 0x7a);
            this.gridView1.Appearance.FixedLine.Options.UseBackColor = true;
            this.gridView1.Appearance.FocusedCell.BackColor = Color.White;
            this.gridView1.Appearance.FocusedCell.ForeColor = Color.Black;
            this.gridView1.Appearance.FocusedCell.Options.UseBackColor = true;
            this.gridView1.Appearance.FocusedCell.Options.UseForeColor = true;
            this.gridView1.Appearance.FocusedRow.BackColor = Color.FromArgb(0x81, 0xab, 0xb1);
            this.gridView1.Appearance.FocusedRow.ForeColor = Color.White;
            this.gridView1.Appearance.FocusedRow.Options.UseBackColor = true;
            this.gridView1.Appearance.FocusedRow.Options.UseForeColor = true;
            this.gridView1.Appearance.FooterPanel.BackColor = Color.FromArgb(0xca, 0xdd, 0xd0);
            this.gridView1.Appearance.FooterPanel.BorderColor = Color.FromArgb(0xca, 0xdd, 0xd0);
            this.gridView1.Appearance.FooterPanel.ForeColor = Color.Black;
            this.gridView1.Appearance.FooterPanel.Options.UseBackColor = true;
            this.gridView1.Appearance.FooterPanel.Options.UseBorderColor = true;
            this.gridView1.Appearance.FooterPanel.Options.UseForeColor = true;
            this.gridView1.Appearance.GroupButton.BackColor = Color.FromArgb(0xb2, 0xd1, 0xbc);
            this.gridView1.Appearance.GroupButton.BorderColor = Color.FromArgb(0xb2, 0xd1, 0xbc);
            this.gridView1.Appearance.GroupButton.Options.UseBackColor = true;
            this.gridView1.Appearance.GroupButton.Options.UseBorderColor = true;
            this.gridView1.Appearance.GroupFooter.BackColor = Color.FromArgb(0xd7, 0xea, 0xdd);
            this.gridView1.Appearance.GroupFooter.BorderColor = Color.FromArgb(0xd7, 0xea, 0xdd);
            this.gridView1.Appearance.GroupFooter.ForeColor = Color.Black;
            this.gridView1.Appearance.GroupFooter.Options.UseBackColor = true;
            this.gridView1.Appearance.GroupFooter.Options.UseBorderColor = true;
            this.gridView1.Appearance.GroupFooter.Options.UseForeColor = true;
            this.gridView1.Appearance.GroupPanel.BackColor = Color.FromArgb(0xf2, 0xf4, 0xec);
            this.gridView1.Appearance.GroupPanel.BackColor2 = Color.White;
            this.gridView1.Appearance.GroupPanel.ForeColor = Color.Black;
            this.gridView1.Appearance.GroupPanel.Options.UseBackColor = true;
            this.gridView1.Appearance.GroupPanel.Options.UseForeColor = true;
            this.gridView1.Appearance.GroupRow.BackColor = Color.FromArgb(0xd7, 0xea, 0xdd);
            this.gridView1.Appearance.GroupRow.BorderColor = Color.FromArgb(0xd7, 0xea, 0xdd);
            this.gridView1.Appearance.GroupRow.ForeColor = Color.Black;
            this.gridView1.Appearance.GroupRow.Options.UseBackColor = true;
            this.gridView1.Appearance.GroupRow.Options.UseBorderColor = true;
            this.gridView1.Appearance.GroupRow.Options.UseForeColor = true;
            this.gridView1.Appearance.HeaderPanel.BackColor = Color.FromArgb(0xd3, 0xe2, 0xd8);
            this.gridView1.Appearance.HeaderPanel.BorderColor = Color.FromArgb(0xd3, 0xe2, 0xd8);
            this.gridView1.Appearance.HeaderPanel.ForeColor = Color.Black;
            this.gridView1.Appearance.HeaderPanel.Options.UseBackColor = true;
            this.gridView1.Appearance.HeaderPanel.Options.UseBorderColor = true;
            this.gridView1.Appearance.HeaderPanel.Options.UseForeColor = true;
            this.gridView1.Appearance.HideSelectionRow.BackColor = Color.FromArgb(0xba, 0xd3, 0xd7);
            this.gridView1.Appearance.HideSelectionRow.ForeColor = Color.FromArgb(0x68, 130, 0x86);
            this.gridView1.Appearance.HideSelectionRow.Options.UseBackColor = true;
            this.gridView1.Appearance.HideSelectionRow.Options.UseForeColor = true;
            this.gridView1.Appearance.HorzLine.BackColor = Color.FromArgb(0xac, 0xc5, 180);
            this.gridView1.Appearance.HorzLine.BorderColor = Color.FromArgb(0x75, 0x88, 0x7a);
            this.gridView1.Appearance.HorzLine.Options.UseBackColor = true;
            this.gridView1.Appearance.HorzLine.Options.UseBorderColor = true;
            this.gridView1.Appearance.OddRow.BackColor = Color.FromArgb(0xf2, 0xf4, 0xec);
            this.gridView1.Appearance.OddRow.BorderColor = Color.FromArgb(0xf2, 0xf4, 0xec);
            this.gridView1.Appearance.OddRow.ForeColor = Color.Black;
            this.gridView1.Appearance.OddRow.Options.UseBackColor = true;
            this.gridView1.Appearance.OddRow.Options.UseBorderColor = true;
            this.gridView1.Appearance.OddRow.Options.UseForeColor = true;
            this.gridView1.Appearance.Preview.BackColor = Color.FromArgb(250, 250, 240);
            this.gridView1.Appearance.Preview.Font = new Font("Verdana", 7.5f);
            this.gridView1.Appearance.Preview.ForeColor = Color.FromArgb(0x68, 130, 0x86);
            this.gridView1.Appearance.Preview.Options.UseBackColor = true;
            this.gridView1.Appearance.Preview.Options.UseFont = true;
            this.gridView1.Appearance.Preview.Options.UseForeColor = true;
            this.gridView1.Appearance.Row.BackColor = Color.FromArgb(0xf2, 0xf4, 0xec);
            this.gridView1.Appearance.Row.ForeColor = Color.Black;
            this.gridView1.Appearance.Row.Options.UseBackColor = true;
            this.gridView1.Appearance.Row.Options.UseForeColor = true;
            this.gridView1.Appearance.RowSeparator.BackColor = Color.FromArgb(0xf2, 0xf4, 0xec);
            this.gridView1.Appearance.RowSeparator.BackColor2 = Color.White;
            this.gridView1.Appearance.RowSeparator.Options.UseBackColor = true;
            this.gridView1.Appearance.SelectedRow.BackColor = Color.FromArgb(0x9f, 0xc9, 0xcf);
            this.gridView1.Appearance.SelectedRow.ForeColor = Color.Black;
            this.gridView1.Appearance.SelectedRow.Options.UseBackColor = true;
            this.gridView1.Appearance.SelectedRow.Options.UseForeColor = true;
            this.gridView1.Appearance.TopNewRow.BackColor = Color.White;
            this.gridView1.Appearance.TopNewRow.Options.UseBackColor = true;
            this.gridView1.Appearance.VertLine.BackColor = Color.FromArgb(0xac, 0xc5, 180);
            this.gridView1.Appearance.VertLine.BorderColor = Color.FromArgb(0x75, 0x88, 0x7a);
            this.gridView1.Appearance.VertLine.Options.UseBackColor = true;
            this.gridView1.Appearance.VertLine.Options.UseBorderColor = true;
            this.gridView1.Columns.AddRange(new GridColumn[] { this.gridds_ma, this.gridds_ten, this.gridds_dvt, this.gridds_id, this.gridds_soluong, this.gridds_quydoi, this.gridds_iddp });
            this.gridView1.GridControl = this.gridds;
            this.gridView1.Name = "gridView1";
            this.gridView1.OptionsView.AutoCalcPreviewLineCount = true;
            this.gridView1.OptionsView.EnableAppearanceEvenRow = true;
            this.gridView1.OptionsView.EnableAppearanceOddRow = true;
            this.gridView1.OptionsView.ShowAutoFilterRow = true;
            this.gridView1.OptionsView.ShowFooter = true;
            this.gridView1.CustomSummaryCalculate += new CustomSummaryEventHandler(this.gridView1_CustomSummaryCalculate);
            this.gridView1.FocusedRowChanged += new FocusedRowChangedEventHandler(this.gridView1_FocusedRowChanged);
            this.gridds_ma.Caption = "M\x00e3 số";
            this.gridds_ma.ColumnEdit = this.repositoryItemTextEdit1;
            this.gridds_ma.FieldName = "madp";
            this.gridds_ma.Name = "gridds_ma";
            this.gridds_ma.OptionsColumn.AllowEdit = false;
            this.gridds_ma.Summary.AddRange(new GridSummaryItem[] { new GridColumnSummaryItem(SummaryItemType.Count, "ma", "Số lượng={0:n0}") });
            this.gridds_ma.Visible = true;
            this.gridds_ma.VisibleIndex = 0;
            this.gridds_ma.Width = 0x52;
            this.repositoryItemTextEdit1.AutoHeight = false;
            this.repositoryItemTextEdit1.Name = "repositoryItemTextEdit1";
            this.repositoryItemTextEdit1.ReadOnly = true;
            this.gridds_ten.Caption = "T\x00ean dược phẩm";
            this.gridds_ten.ColumnEdit = this.repositoryItemTextEdit1;
            this.gridds_ten.FieldName = "tendp";
            this.gridds_ten.Name = "gridds_ten";
            this.gridds_ten.OptionsColumn.AllowEdit = false;
            this.gridds_ten.OptionsColumn.FixedWidth = true;
            this.gridds_ten.Visible = true;
            this.gridds_ten.VisibleIndex = 1;
            this.gridds_ten.Width = 0x20c;
            this.gridds_dvt.Caption = "ĐVT";
            this.gridds_dvt.ColumnEdit = this.repositoryItemTextEdit1;
            this.gridds_dvt.FieldName = "dvt";
            this.gridds_dvt.Name = "gridds_dvt";
            this.gridds_dvt.OptionsColumn.AllowEdit = false;
            this.gridds_dvt.Visible = true;
            this.gridds_dvt.VisibleIndex = 2;
            this.gridds_dvt.Width = 0x39;
            this.gridds_id.Caption = "id";
            this.gridds_id.FieldName = "id";
            this.gridds_id.Name = "gridds_id";
            this.gridds_soluong.Caption = "Số lượng";
            this.gridds_soluong.FieldName = "soluong";
            this.gridds_soluong.Name = "gridds_soluong";
            this.gridds_soluong.OptionsColumn.ReadOnly = true;
            this.gridds_soluong.Visible = true;
            this.gridds_soluong.VisibleIndex = 3;
            this.gridds_soluong.Width = 90;
            this.gridds_quydoi.Caption = "Quy đổi";
            this.gridds_quydoi.FieldName = "ten";
            this.gridds_quydoi.Name = "gridds_quydoi";
            this.gridds_quydoi.OptionsColumn.ReadOnly = true;
            this.gridds_quydoi.Visible = true;
            this.gridds_quydoi.VisibleIndex = 4;
            this.gridds_quydoi.Width = 0x176;
            this.gridds_iddp.Caption = "iddp";
            this.gridds_iddp.FieldName = "iddp";
            this.gridds_iddp.Name = "gridds_iddp";
            this.gridds.Anchor = AnchorStyles.Right | AnchorStyles.Left | AnchorStyles.Bottom | AnchorStyles.Top;
            this.gridds.Location = new Point(0, 0x33);
            this.gridds.MainView = this.gridView1;
            this.gridds.Name = "gridds";
            this.gridds.RepositoryItems.AddRange(new RepositoryItem[] { this.repositoryItemTextEdit1 });
            this.gridds.Size = new Size(0x392, 0x132);
            this.gridds.TabIndex = 11;
            this.gridds.ViewCollection.AddRange(new BaseView[] { this.gridView1 });
            this.btnboqua.Anchor = AnchorStyles.Bottom;
            this.btnboqua.Image = Properties.Resources.imgundo;// (Image)manager.GetObject("btnboqua.Image");
            this.btnboqua.Location = new Point(0x14c, 0x185);
            this.btnboqua.Name = "btnboqua";
            this.btnboqua.Size = new Size(0x57, 0x17);
            this.btnboqua.TabIndex = 8;
            this.btnboqua.Text = " &Bỏ qua [F4]";
            this.btnboqua.Click += new EventHandler(this.btnboqua_Click);
            this.btnin.Anchor = AnchorStyles.Bottom;
            this.btnin.Image = Properties.Resources.imgprint;// (Image)manager.GetObject("btnin.Image");
            this.btnin.Location = new Point(0x1f3, 0x185);
            this.btnin.Name = "btnin";
            this.btnin.Size = new Size(0x30, 0x17);
            this.btnin.TabIndex = 10;
            this.btnin.Text = " &In";
            this.btnin.Click += new EventHandler(this.btnin_Click);
            this.btnimport.Anchor = AnchorStyles.Bottom;
            this.btnimport.Image = Properties.Resources.imgimportexcel;// (Image)manager.GetObject("btnimport.Image");
            this.btnimport.Location = new Point(0x225, 0x185);
            this.btnimport.Name = "btnimport";
            this.btnimport.Size = new Size(0x4b, 0x17);
            this.btnimport.TabIndex = 12;
            this.btnimport.Text = " &Chọn file";
            this.btnimport.Click += new EventHandler(this.btnimport_Click);
            this.ctrdanhsach_vp.ChieuRongTuDong = true;
            this.ctrdanhsach_vp.DanhSachCotHienThi = "";
            this.ctrdanhsach_vp.DanhSachCotHienThi_kt = "";
            this.ctrdanhsach_vp.Location = new Point(0x2a0, 0x185);
            this.ctrdanhsach_vp.Name = "ctrdanhsach_vp";
            this.ctrdanhsach_vp.pRowsCountDown = 5;
            this.ctrdanhsach_vp.Size = new Size(60, 0x13);
            this.ctrdanhsach_vp.TabIndex = 2;
            this.ctrdanhsach_vp.Visible = false;
            this.ctrdanhsach_vp.Validated += new EventHandler(this.ctrdanhsach_vp_Validated);
            this.label3.Anchor = AnchorStyles.Right | AnchorStyles.Bottom;
            this.label3.Font = new Font("Tahoma", 10f);
            this.label3.Location = new Point(0x319, 0x169);
            this.label3.Name = "label3";
            this.label3.Size = new Size(0x12, 0x13);
            this.label3.TabIndex = 2;
            this.label3.Text = "=";
            this.label3.TextAlign = ContentAlignment.TopRight;
            this.txtten.Anchor = AnchorStyles.Right | AnchorStyles.Bottom;
            this.txtten.Location = new Point(0x2af, 0x16b);
            this.txtten.Name = "txtten";
            this.txtten.Size = new Size(0x69, 20);
            this.txtten.TabIndex = 3;
            this.txtten.KeyDown += new KeyEventHandler(this.ucDMSanPham_KeyDown);
            this.txtsoluong.Anchor = AnchorStyles.Right | AnchorStyles.Bottom;
            this.txtsoluong.Location = new Point(0x328, 0x169);
            this.txtsoluong.Name = "txtsoluong";
            this.txtsoluong.Properties.Appearance.Font = new Font("Tahoma", 10f);
            this.txtsoluong.Properties.Appearance.Options.UseFont = true;
            this.txtsoluong.Properties.DisplayFormat.FormatString = "n0";
            this.txtsoluong.Properties.DisplayFormat.FormatType = FormatType.Numeric;
            this.txtsoluong.Properties.EditFormat.FormatString = "n0";
            this.txtsoluong.Properties.EditFormat.FormatType = FormatType.Numeric;
            this.txtsoluong.Properties.Mask.EditMask = "n0";
            this.txtsoluong.Properties.Mask.MaskType = MaskType.Numeric;
            this.txtsoluong.Size = new Size(0x2e, 0x16);
            this.txtsoluong.TabIndex = 4;
            this.txtsoluong.KeyDown += new KeyEventHandler(this.ucDMSanPham_KeyDown);
            base.AutoScaleDimensions = new SizeF(6f, 13f);
            base.AutoScaleMode = AutoScaleMode.Font;
            base.Controls.Add(this.txtsoluong);
            base.Controls.Add(this.ctrdanhsach_vp);
            base.Controls.Add(this.txtten);
            base.Controls.Add(this.txtma);
            base.Controls.Add(this.gridds);
            base.Controls.Add(this.btnketthuc);
            base.Controls.Add(this.btnimport);
            base.Controls.Add(this.btnin);
            base.Controls.Add(this.btnxoa);
            base.Controls.Add(this.btnboqua);
            base.Controls.Add(this.btnsua);
            base.Controls.Add(this.btnluu);
            base.Controls.Add(this.btnmoi);
            base.Controls.Add(this.txttenduocpham);
            base.Controls.Add(this.txtdvt);
            base.Controls.Add(this.label3);
            base.Controls.Add(this.label2);
            base.Controls.Add(this.label1);
            base.Name = "ucd_dmquydoi";
            base.Size = new Size(0x392, 0x19f);
            base.Load += new EventHandler(this.ucDMSanPham_Load);
            base.KeyDown += new KeyEventHandler(this.ucDMSanPham_KeyDown);
            this.txtma.Properties.EndInit();
            this.txttenduocpham.Properties.EndInit();
            this.txtdvt.Properties.EndInit();
            this.gridView1.EndInit();
            this.repositoryItemTextEdit1.EndInit();
            this.gridds.EndInit();
            this.txtten.Properties.EndInit();
            this.txtsoluong.Properties.EndInit();
            base.ResumeLayout(false);
        }

        private void txtten_Validated(object sender, EventArgs e)
        {
            try
            {
                this.txttenduocpham.Text = this.txttenduocpham.Text.Substring(0, 1).ToUpper() + this.txttenduocpham.Text.Substring(1);
            }
            catch
            {
            }
        }

        private void txttenduocpham_Enter(object sender, EventArgs e)
        {
            this.ctrdanhsach_vp.Width = (this.txtdvt.Location.X + this.txtdvt.Width) - this.txtma.Location.X;
            this.ctrdanhsach_vp.Height = 90;
            this.ctrdanhsach_vp.Location = new Point(this.txtma.Location.X, (this.txtma.Location.Y - this.ctrdanhsach_vp.Height) - 1);
            this.ctrdanhsach_vp.DanhSachCotHienThi_kt = string.Concat(new object[] { this.txtma.Width, ",", (this.ctrdanhsach_vp.Width - 0x34) - this.txtma.Width, ",", 50 });
        }

        private void txttenduocpham_KeyDown(object sender, KeyEventArgs e)
        {
            if ((e.KeyCode == Keys.Down) || (e.KeyCode == Keys.Up))
            {
                this.ctrdanhsach_vp.Visible = true;
                this.ctrdanhsach_vp.Focus();
            }
            else if (e.KeyCode == Keys.Escape)
            {
                this.ctrdanhsach_vp.Visible = false;
            }
            else if (e.KeyCode == Keys.Enter)
            {
                this.ctrdanhsach_vp.Visible = false;
                this.ucDMSanPham_KeyDown(sender, e);
            }
            else
            {
                this.ucDMSanPham_KeyDown(sender, e);
            }
        }

        private void txttenduocpham_TextChanged(object sender, EventArgs e)
        {
            if (this.txttenduocpham.IsEditorActive)
            {
                this.ctrdanhsach_vp.Visible = true;
                this.ctrdanhsach_vp.Locdulieu(this.txttenduocpham.Text);
            }
        }

        private void ucDMSanPham_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
            {
                SendKeys.Send("{Tab}");
            }
            else if (e.KeyCode == Keys.F2)
            {
                if (this.btnmoi.Enabled)
                {
                    this.btnmoi_Click(null, null);
                }
            }
            else if (e.KeyCode == Keys.F3)
            {
                if (this.btnsua.Enabled)
                {
                    this.btnsua_Click(null, null);
                }
            }
            else if (e.KeyCode == Keys.F4)
            {
                if (this.btnboqua.Enabled)
                {
                    this.btnboqua_Click(null, null);
                }
            }
            else if (e.KeyCode == Keys.F5)
            {
                if (this.btnluu.Enabled)
                {
                    this.btnluu_Click(null, null);
                }
            }
            else if (e.KeyCode == Keys.F7)
            {
                if (this.btnxoa.Enabled)
                {
                    this.btnxoa_Click(null, null);
                }
            }
            else if ((e.KeyCode == Keys.F12) && this.btnketthuc.Enabled)
            {
                this.btnketthuc_Click(null, null);
            }
        }

        private void ucDMSanPham_Load(object sender, EventArgs e)
        {
            if (this._dto != null)
            {
                this._dto = new dtoDDMQuyDoi(this._condata);
            }
            this._xuli = new General(this._condata);
            this.f_loaddata_dmduocpham();
            this.f_loaddata_quydoi();
            this.btnboqua_Click(null, null);
            this.f_loadinfo_dmsanpham(0);
            if (this._dtodp != null)
            {
                this.btnmoi_Click(null, null);
                this.f_load_thongtinduocpham(this._dtodp.pID, this._dtodp.pMA, this._dtodp.pTEN, this._dtodp.pDVT);
                this.txtten.Focus();
            }
        }
    }
}

